package com.autumn.scheduler.api.constant;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Api 常量
 * 
 * @author 老码农
 *
 *         2018-07-04 16:54:54
 */
public class ApiConstants {

	/**
	 * Trigger 类型
	 * 
	 * @author 杨昌国 2018-03-19 23:36:29
	 */
	public static class TriggerType {
		/**
		 * CronTrigger
		 */
		public final static String CRON = "CRON";

		/**
		 * SimpleTrigger
		 */
		public final static String SIMPLE = "SIMPLE";

		/**
		 * CalendarIntervalTrigger
		 */
		public final static String CAL_INT = "SIMPLE";

		/**
		 * DailyTimeIntervalTrigger
		 */
		public final static String DAILY_TIME_INT = "DAILY_I";

		private final static Map<String, String> MESSAGE_MAP = new HashMap<>();
		static {
			MESSAGE_MAP.put(CRON, "Cron 表达式");
			MESSAGE_MAP.put(SIMPLE, "简单定时触发器");
			MESSAGE_MAP.put(CAL_INT, "日历定时触发器");
			MESSAGE_MAP.put(DAILY_TIME_INT, "日期触发器");
		}

		/**
		 * 获取消息
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getMessage(String value) {
			String msg = MESSAGE_MAP.get(value);
			if (msg == null) {
				msg = "";
			}
			return msg;
		}

		/**
		 * 创建项目集合
		 * 
		 * @return
		 *
		 */
		public static List<ConstantItem<String>> createItems() {
			return ConstantItem.createItems(MESSAGE_MAP);
		}
	}

	/**
	 * 执行后操作
	 * 
	 * @author 老码农
	 *
	 *         2018-03-19 21:02:00
	 */
	public static class ExecuteOperation {
		/**
		 * 执行后操作 无任何操作
		 */
		public final static int NONE = 0;

		/**
		 * 执行后操作 暂停
		 */
		public final static int PAUSE = 1;

		/**
		 * 执行后操作 删除
		 */
		public final static int DELETE = 2;

		private final static Map<Integer, String> MESSAGE_MAP = new HashMap<>();
		static {
			MESSAGE_MAP.put(NONE, " 无操作");
			MESSAGE_MAP.put(PAUSE, "暂停");
			MESSAGE_MAP.put(DELETE, "删除");
		}

		/**
		 * 获取消息
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getMessage(int value) {
			String msg = MESSAGE_MAP.get(value);
			if (msg == null) {
				msg = "";
			}
			return msg;
		}

		/**
		 * 创建项目集合
		 * 
		 * @return
		 *
		 */
		public static List<ConstantItem<Integer>> createItems() {
			return ConstantItem.createItems(MESSAGE_MAP);
		}
	}

	/**
	 * 运行状态 描述：
	 * 
	 * @author 杨昌国 2018-03-20 01:01:46
	 */
	public static class RunState {
		/**
		 * 成功
		 */
		public final static int SUCCESS = 1;
		/**
		 * 失败
		 */
		public final static int FAIL = -1;
	}

	/**
	 * 时间单位
	 * 
	 * @author 老码农
	 *
	 *         2018-03-23 14:46:53
	 */
	public static class JobIntervalUnit {

		/**
		 * 毫秒
		 */
		public static final String MILLISECOND = "MILLISECOND";

		/**
		 * 秒
		 */
		public static final String SECOND = "SECOND";

		/**
		 * 分钟
		 */
		public static final String MINUTE = "MINUTE";

		/**
		 * 小时
		 */
		public static final String HOUR = "HOUR";

		/**
		 * 天
		 */
		public static final String DAY = "DAY";

		/**
		 * 周
		 */
		public static final String WEEK = "WEEK";

		/**
		 * 月
		 */
		public static final String MONTH = "MONTH";

		/**
		 * 年
		 */
		public static final String YEAR = "YEAR";

		private final static Map<String, String> INTERVAL_UNIT_MAP = new HashMap<>();
		static {
			INTERVAL_UNIT_MAP.put(MILLISECOND, "毫秒");
			INTERVAL_UNIT_MAP.put(SECOND, "秒");
			INTERVAL_UNIT_MAP.put(MINUTE, "分钟");
			INTERVAL_UNIT_MAP.put(HOUR, "小时");
			INTERVAL_UNIT_MAP.put(DAY, "天");
			INTERVAL_UNIT_MAP.put(WEEK, "星期");
			INTERVAL_UNIT_MAP.put(MONTH, "月");
			INTERVAL_UNIT_MAP.put(YEAR, "年");
		}

		/**
		 * 获取时间单位信息
		 * 
		 * @param name
		 *            名称
		 * @return
		 */
		public static String getIntervalUnit(String name) {
			if (name != null) {
				name = name.toUpperCase();
			}
			String msg = INTERVAL_UNIT_MAP.get(name);
			if (msg == null) {
				msg = "";
			}
			return msg;
		}

		/**
		 * 创建项目集合
		 * 
		 * @return
		 *
		 */
		public static List<ConstantItem<String>> createItems() {
			return ConstantItem.createItems(INTERVAL_UNIT_MAP);
		}
	}

	/**
	 * 任务触发状态
	 * 
	 * @author 老码农
	 *
	 *         2018-03-23 16:06:38
	 */
	public static class JobTriggerState {

		/**
		 * 等待
		 */
		public static final String WAITING = "WAITING";

		/**
		 * 活动中
		 */
		public static final String ACQUIRED = "ACQUIRED";

		/**
		 * 执行中
		 */
		public static final String EXECUTING = "EXECUTING";

		/**
		 * 完成
		 */
		public static final String COMPLETE = "COMPLETE";

		/**
		 * 阻塞
		 */
		public static final String BLOCKED = "BLOCKED";

		/**
		 * 错误
		 */
		public static final String ERROR = "ERROR";

		/**
		 * 暂停
		 */
		public static final String PAUSED = "PAUSED";

		/**
		 * 暂停并阻塞
		 */
		public static final String PAUSED_BLOCKED = "PAUSED_BLOCKED";

		/**
		 * 删除
		 */
		public static final String DELETED = "DELETED";

		private final static Map<String, String> MESSAGE_MAP = new HashMap<>();
		static {
			MESSAGE_MAP.put(WAITING, "等待");
			MESSAGE_MAP.put(ACQUIRED, "活动中");
			MESSAGE_MAP.put(EXECUTING, "执行中");
			MESSAGE_MAP.put(COMPLETE, "完成");
			MESSAGE_MAP.put(BLOCKED, "阻塞");
			MESSAGE_MAP.put(ERROR, "错误");
			MESSAGE_MAP.put(PAUSED, "暂停");
			MESSAGE_MAP.put(PAUSED_BLOCKED, "暂停并阻塞");
			MESSAGE_MAP.put(DELETED, "删除");
		}

		/**
		 * 获取消息
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getMessage(String name) {
			String msg = MESSAGE_MAP.get(name);
			if (msg == null) {
				msg = "";
			}
			return msg;
		}

		/**
		 * 创建项目集合
		 * 
		 * @return
		 *
		 */
		public static List<ConstantItem<String>> createItems() {
			return ConstantItem.createItems(MESSAGE_MAP);
		}
	}

	/**
	 * 队列运行状态
	 * 
	 * @author 杨昌国 2018-03-20 12:38:49
	 */
	public static class QueueRunState {

		/**
		 * 发送失败
		 */
		public final static int SEND_FAIL = -1;

		/**
		 * 发送成功
		 */
		public final static int SEND_SUCCESS = 1;

		/**
		 * 作业失败
		 */
		public final static int JOB_FAIL = -10;

		/**
		 * 作业成功
		 */
		public final static int JOB_SUCCESS = 10;

		private final static Map<Integer, String> MESSAGE_MAP = new HashMap<>();

		static {
			MESSAGE_MAP.put(SEND_FAIL, "发送失败");
			MESSAGE_MAP.put(SEND_SUCCESS, "发送成功");
			MESSAGE_MAP.put(JOB_FAIL, "作业失败");
			MESSAGE_MAP.put(JOB_SUCCESS, "作业成功");
		}

		/**
		 * 获取消息
		 * 
		 * @param value
		 *            值
		 * @return
		 */
		public static String getMessage(int value) {
			String msg = MESSAGE_MAP.get(value);
			if (msg == null) {
				msg = "";
			}
			return msg;
		}
	}
}
